import {
  fetchMchList
} from '@/services/mch/MchCommon';

export default {
  namespace: 'MchCommon',

  state: {
    mchList: [],
  },

  effects: {
    * fetchMchList({}, {call, put}) {
      const response = yield call(fetchMchList);
      if (response.code === 0) {
        yield put({
          type: 'chgMchList',
          payload: response.data.map(d => {
            d.value = d.code;
            d.label = `${d.name}`
            return d;
          }),
        });
      }
    },

    * fetchMchForIdList({}, {call, put}) {
      const response = yield call(fetchMchList);
      if (response.code === 0) {
        yield put({
          type: 'chgMchList',
          payload: response.data.map(d => {
            d.value = d.id;
            d.label = `${d.name}【id:${d.id}】`
            return d;
          }),
        });
      }
    },
  },

  reducers: {
    chgMchList(state, action) {
      return {
        ...state,
        mchList: action.payload,
      };
    },
  },

};
